﻿using Api1.Model;
using Api1.Util;
using System;
using System.Collections.Generic;


namespace Api1.Service
{
    class SingleVersionService
    {
        private static SingleVersionService instance;
        public SingleVersionService()
        {

        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static SingleVersionService GetInstance()
        {
            if (instance == null)
            {
                return new SingleVersionService();
            }
            else
            {
                return instance;
            }
        }
        /// <summary>
        /// 入场操作
        /// </summary>
        /// <param name="Card_NO"></param>
        /// <returns></returns>
        public Dictionary<String, Object> CheckIn(String Card_NO)
        {
            Interfaces model=InterfaceService.GetInstance().FindByCardno(Card_NO);
            if (model == null)
            {
                return HttpClient.Error("无效的卡号");
            }
            else if (model.Contract_Status != 1)
            {
                return HttpClient.Error("合同号无效");
            }
            else if (DateTime.Now.ToString("yyyy-MM-dd").CompareTo(model.Start_Date)<0|| DateTime.Now.ToString("yyyy-MM-dd").CompareTo(model.End_Date) >0) {

                return HttpClient.Error("不在合同有效期内");
            }
            if (model.Membership_Type == 1)
            {// 次卡
                if (model.Surplus_Num < 1)
                {
                    return HttpClient.Error("卡剩余次数不足");
                }
                else {
                    //次卡减一
                    InterfaceService.ExcuteSql(String.Format("update m_interface set surplus_num=surplus_num-1 where card_no='{0}'", Card_NO));
                    return HttpClient.Success("成功");
                }
            }
            else if(model.Membership_Type==2)
            {//年限卡
                return HttpClient.Success("成功");
            }
            return HttpClient.Error("错误的卡类型");
        }
        /// <summary>
        /// 出场操作
        /// </summary>
        /// <param name="Card_no"></param>
        /// <returns></returns>
        public Dictionary<String, Object> CheckOut(String Card_no) {
            return HttpClient.Success("成功");
        }
    }
}
